<?php
namespace app\index\controller;

use think\Controller;
use think\Cache;
use think\Db;
use app\index\model\imgModel;
class Index extends Controller
{
    
    // public function text(){
    //     $file_path = "url.txt";
    //     if(file_exists($file_path)){
    //         $str = file_get_contents($file_path);//将整个文件内容读入到一个字符串中
    //         $str = str_replace("rn","<br/>",$str);
    //         $arr = array_unique(explode("\n",$str));
    //     // echo $arr;
    //         // var_dump($arr);
    //         foreach ($arr as $value) {
    //             $cneame_url = get_random(rand(16,32),"QAZWSXEDCRFVTGBYHNUJMIKOLPqazwsxedcrfvtgbyhnujmiklop1234567890");
    //             $value = "/$cneame_url.html".$value;
    //             // var_dump($value);
    //             echo($value);
    //         }
    //     }
    // }
    
    public function eos_get(){
        header('Access-Control-Allow-Origin:*');
        // if(!wx_mobile()){
        //     $this->redirect("https://xw.qq.com/");
        // }
        $ddh2 = $_GET['bucket'];
        
        if(empty($ddh2)){
             $this->redirect("https://xw.qq.com/");
        }
        
        $info = Cache::store('redis')->has('yldwz'.$ddh2);

		if(!$info || $info === "null"){
		    
		    $info = Db::name('dwz')->where(['ddh' => $ddh2])->find();
		    Cache::store('redis')->set('yldwz'.$ddh2,json_encode($info),14400);
		    
		}else{
		    
		    $info = Cache::store('redis')->get('yldwz'.$ddh2);
		    
		}
        
        if(!$info || $info['status'] != 1){
            $this->redirect("http://a.bdydns.com/");
        }
        
        
        if($info['ddh'] !== $ddh2){
            $this->redirect("https://xw.qq.com/");
        }
        $res['code']='';
        $res['body'] = '';
        if($info['ddh'] == $ddh2){
            $res['code']=200;
            $res['body'] = $info['dwz'];
        }else{
            $res['code']=200;
            $res['body'] = '';
        }
        return json_encode($res);
    }
    
    //短信
    // public function duanxin(){
    //     die;
    //     $res = Db::name('ip')->where(true)->order('id desc')->find();  
         
    //     $red = Db::name('duanxin')->where(['id' => 1])->find();
     
    //     if($res['shijian'] + 120 < time() && $red['time'] < time()){
        
         
    //         Db::name('duanxin')->where(['id' => 1])->update(['time' => time() + 300]);
    //         $cpid      = 26600;
            
    //         $userpa    = 'htx11223344';
            
    //         $password  = md5($userpa.'_'.time().'_topsky');
            
    //         $channelid = 32083;
            
    //         $timestamp = time();
            
    //         $yzm       = '3'.rand(100,999);
            
    //         $msg       = "验证码：".$yzm."，该验证码3分钟有效，请勿泄露！";
            
    //         $tele      = "";
    //         $url       = "http://admin.sms9.net/houtai/sms.php?cpid={$cpid}&password={$password}&channelid={$channelid}&tele={$tele}&msg={$msg}&timestamp=".$timestamp;
    //         $url2      = file_get_contents($url);
    //     }
    // }

    public function index()
    {
        $this->redirect("https://xw.qq.com/");
    }
    
    // public function test1(){
    //     $where['shijian'] = ['between','1605807000,1605810600'];
    //     $where['type'] = 2;
    //     $list = Db::name('order')->where($where)->select();
    //     foreach ($list as $v){
    //             $data = [];
    //              $zyid = $v['zyid'];
    //              $userid = $v['userid'];
    //              $ddh = $v['orderid'];
    //             $ip = $v['ip'];
    //             // //
    //             $ddh2 = substr($ddh, 0, 10);
    //             $data = [];
    //             $data['ip'] = $ip;
    //             $data['userid'] = $userid;
    //             $data['ddh'] = $ddh2;
    //             $data['zyid'] = $zyid;
    //             $data['ddh2'] = $ddh;
    //             $data['zt'] = "已付";
    //             $data['shijian'] = time();
    //             $data['openid']  = $v['uopenid'];
                
    //             $data['uopenid']  = $v['uopenid'];
               
    //             Db::name("ip")->insert($data);
            
    //     }
    // }

    public function jubao()
    {
        if(!wx_mobile()){
            $this->redirect("https://xw.qq.com/");
        }
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
              $ip = getIP();
          
        }else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
              $ip = explode(',', getIP())[0];
        
        }else{
              $ip = getIP();
        } 
        $shijian = date('Y-m-d H:i:s' , time());
        $data = [];
        $data['shijian'] = $shijian;
        $data['ip'] = $ip;
        $data['zt'] = "禁止访问";
        $data['neirong'] = trim(htmlspecialchars(input("post.content"),ENT_QUOTES));
        $data['typeto']  = trim(htmlspecialchars(input("post.type"),ENT_QUOTES));
        $data['uopenid'] = trim(htmlspecialchars(input("post.uopenid"),ENT_QUOTES));
        Db::name("ts")->insert($data);
        echo 1;
    }
    
    //投诉
    public function tousu()
    {
        if(!is_weixin()){
            $this->redirect("https://xw.qq.com/");
        }
        $ename   = Cache::store('redis')->get('ylluodi');
        
        $uopenid = input('uopenid');
        
       
        $this->assign('uopenid', $uopenid); //当前页
       
        return $this->fetch();
    }

    /***
    * 主入口
    */
    public function hezi()
    {
      
        $userid      = trim(htmlspecialchars(input('userid'),ENT_QUOTES));
        $sing        = trim(htmlspecialchars(input('sing'),ENT_QUOTES));
        $ddh2        = trim(htmlspecialchars(input('ddh'),ENT_QUOTES));
        $id          = trim(htmlspecialchars(input('id/d',0),ENT_QUOTES));
        $uopenid     = trim(htmlspecialchars(input('uopenid'),ENT_QUOTES));
        $gettype     = trim(htmlspecialchars(input('type/d',0),ENT_QUOTES));//type = 1000 是用户已打赏
        $count       = trim(htmlspecialchars(input('count/d',0),ENT_QUOTES));
        $sy          = trim(htmlspecialchars(input('shouye/d',0),ENT_QUOTES));//type = 1000 是用户已打赏
        
        
        if(empty($userid) || empty($ddh2) || empty($uopenid)){
             $this->redirect("https://xw.qq.com/3");
        } 
        
        if(mb_strlen($uopenid) != 28 || mb_strlen($ddh2) != 10){
             $this->redirect("https://xw.qq.com/1");
        }
        
        if(!wx_mobile()){
            $this->redirect("https://xw.qq.com/2");
        }
       
        $info = Cache::store('redis')->has('yldwz'.$ddh2);

		if(!$info || $info === "null"){
		    $info = Db::name('dwz')->where(['ddh' => $ddh2])->find();
		    Cache::store('redis')->set('yldwz'.$ddh2,json_encode($info),14400);
		}else{
		    $info = Cache::store('redis')->get('yldwz'.$ddh2);
		}
        
        if(!$info || $info['status'] != 1){
            $this->redirect("http://a.bdydns.com/");
        }
        
        $jiami_id   = $userid;
        $userid     = $info['userid'];
        $dd2        = $info['ddh'];
        $id         = $info['sid'];
        $dwz_type   = $info['dwz_type'];
        $createtime = $info['create_time'];
        $shijian    = $info['xiaoshi'];
        $guoqi      = $info['xiaoshi'];
        $tuif       = $info['tuif'];
        $tuit       = $info['tuit'];
        
        // if($userid == 201168){
        //     var_dump($_SERVER);
        //     die;
        // }
        
        if(empty($info['tui']) || $info['tui'] === 0){
             $tui['url'] = null;
        }else{
             $tui['url'] = $info['tui']; 
        }
        
        $status = Db::name("member")->where(['id' => $userid])->value('status');
        
        if($status == 0){
            $this->redirect("https://xw.qq.com/");
        }
        
        //片金额
        $btmoney =  Db::name("pian")->where(['userid' => $userid])->value('b_money');
        
        //包天
        $info    = Db::name('baotian')->where(['uopenid' => $uopenid])->order('id desc')->find();
        
        if($info && $info['end_time'] > time()){
            $is_baotian = 1;
        }else{
            $is_baotian = 0;
        }
        
        //点击打赏视频
        // if($sy == 1){
        //     $yemian  = "hezi1";
        // }
        
        // $zhibo    = Db::name('config')->where(['name' => 'zhibo'])->value('value');
        // $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
        // if($zhibo == 1 && $dwz_type == 1 && $sy != 1){
        //      $zhibo    = "http://" . $ename . "/index/index/zhibo.html?userid=" . $jiami_id ."&ddh=". $ddh2."&uopenid=".$uopenid."&shouye=1";
        //      $this->redirect($zhibo);
        // }
        
        // if($dwz_type == 1 && $zhibo == 0 && $sy != 1){
        //     $yemian  = "hezi1";
        //     $shouye  = '';
        //     $zhibo  = '';
            
        // }else{
        //     $yemian  = "hezi1";
        //     $shouye  = '';
        //     $zhibo  = '';
        // }
        
        $yemian  = "hezi1";
        $shouye  = '';
        $zhibo  = '';
        
        return $this->fetch($yemian,[
             'userid' => $jiami_id,
             'is_baotian' => $is_baotian,
             'btmoney' => $btmoney,
             'tui' => $tui,
             'ddh' => $ddh2,
             'uopenid' => $uopenid,
             'gettype' => $gettype,
             'id' => $id,
             'shouye' => $shouye,
             'zhibo'  =>$zhibo,
             'tuif' => $tuif,
             'tuit' => $tuit
        ]);
       
    }
    
    
    /**
     * 随机生成字符串
     * @param int $length
     * @return null|string
     */
    public static function getRandChar($length = 8){
      $str = null;
      $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
      $max = strlen($strPol)-1;
      
      for($i=0;$i<$length;$i++){
        $str.=$strPol[rand(0,$max)]; //rand($min,$max)生成介于min和max两个数之间的一个随机整数
      }
      
      return $str;
    }
    
    
  
    
    
    public function shuju(){
        header('Access-Control-Allow-Origin:*');  
        $userid      = trim(htmlspecialchars(input('userid'),ENT_QUOTES));
        $ddh2        = trim(htmlspecialchars(input('ddh'),ENT_QUOTES));
        $id          = trim(htmlspecialchars(input('id/d',0),ENT_QUOTES));
        $uopenid     = trim(htmlspecialchars(input('uopenid'),ENT_QUOTES));
        $gettype     = trim(htmlspecialchars(input('type/d',0),ENT_QUOTES));//type = 1000 是用户已打赏
        $sousuo      = trim(htmlspecialchars(input('sousuo'),ENT_QUOTES));
        $Nowpage     = input('page') ? input('page'):1;
        $sptype      = trim(htmlspecialchars(input('sptype/d',0),ENT_QUOTES));
        if(empty($userid) || empty($ddh2) || empty($uopenid) || $ddh2 == "qg65ZHT8cq"  || $ddh2 == "yupUUE5kg2"){
              $this->redirect("https://xw.qq.com/");
        }
        
        if(mb_strlen($uopenid) != 28 || mb_strlen($ddh2) != 10){
             
              header('Location:https://www.baidu.com/');exit;
        }
        
        if(!wx_mobile()){
             header('Location:https://www.baidu.com/');exit;
        }
       
      
        $info = Cache::store('redis')->has('yldwz'.$ddh2);

		if(!$info || $info === "null"){
		      $info = Db::name('dwz')->where(['ddh' => $ddh2])->find();
		      Cache::store('redis')->set('yldwz'.$ddh2,json_encode($info),86400);
		}else{
		    $info = Cache::store('redis')->get('yldwz'.$ddh2);
		}
        
        
    //   $info = Db::name('dwz')->where(['ddh' => $ddh2])->find();
        
        if(empty($info)){
            die('参数错误');
        }
        
    
     
        
        $jiami_id = $userid;
        
        $userid   = $info['userid'];
        $dd2      = $info['ddh'];
        $id       = $info['sid'];
        
      
       
        
        if($sptype && $gettype != 159 && $gettype != 1000){
            // $gettype = $sptype;
        }
        
        
        //查询已购买的片源id
       
        if($gettype == 1000){
           
            $yifutime = time() - 86400;
            
            $end_time = time();
            
            $map['uopenid']    = $uopenid;
            
            $map['shijian']     = ['>=', $yifutime];
            
            // $map['end_time']     = ['gt', $end_time];
            $lists    = Db::name("ip")->where($map)->order('id desc')->select();
            if($lists){
                 foreach($lists as $v){
                       $zyid[] = $v['zyid'];
                 }
                $lists = Db::name("gongyou")->where(['id' => ['in',$zyid]])->limit(30)->order('cs desc')->select();
            }
        }

    
        
          
          //默认
            
           if($gettype == 0){
               
            if(1 == rand(1,4) || $Nowpage <= 4){
                
              
                $wheretwos['count'] = ['gt',10];
              
                if(1 == rand(1,2)){
                  $wheretwos['count'] = ['gt',20]; 
                }
            }else{
                $wheretwos['count'] = ['gt',10];
                if(1 == rand(1,4)){
                  $wheretwos['count'] = ['gt',20]; 
                }
            }
           
             $wheretwos['del'] = 1;
             if($sptype > 0){
                // if(1 == rand(1,2)){
                //   $wheretwos['type'] = $sptype;
                //   $wheretwos['count'] = ['gt',800];
                // }
                 
                 $lists = Db::name("gongyou")->where($wheretwos)->order('rand()')->limit(20)->field('id,photo,url,name,pianku,count,times')->select();
            }else{
                $lists = Db::name("gongyou")->where($wheretwos)->order('rand()')->limit(20)->field('id,photo,url,name,pianku,count,times')->select();
            }
            
            
            $type = 1;
        }
        
        
        //今日新片
        if($gettype == 158)
        {
            $wheretwos['del'] =  1;
          
             if(1 == rand(1,6)){
                $wheretwos['count'] = ['gt',10];
             }else{
                 
              if(1 == rand(1,5)){
                    // $timer = date("Y-m-d",strtotime("-150 day"));
                      $wheretwos['count']   = ['gt',0];
                }else{
                    //  $timer = date("Y-m-d",strtotime("-30 day"));
                     $wheretwos['count']   = ['gt',0];
                }
              
                $wheretwos['shijian'] = ['gt',$timer];
              
                $wheretwos['yi']   = 0;
             }
           
            $lists = Db::name("gongyou")->where($wheretwos)->order('rand()')->limit(20)->field('id,photo,url,name,pianku,count,times')->select();
        }
        
        //今日最热
        if($gettype == 160)
        {
            $wheretwos['del']  = 1;
          
             if(1 == rand(1,2)){
                $wheretwos['count'] = ['gt',10];
             }else{
                $wheretwos['count'] = ['gt',10]; 
             }
             
             
             if(1 == rand(1,3)){
                $wheretwos['count'] = ['gt',0];
             }
          
            $lists = Db::name("gongyou")->where($wheretwos)->order('rand()')->limit(20)->field('id,photo,url,name,pianku,count,times')->select();
           
        }
        
        
        //点击分类
        if($gettype != 1000 && $gettype != 0 && $gettype != 158 && $gettype != 160){
         
             $wheretwos['del'] = 1;
            
             $wheretwos['type']  = $gettype;
             
            //   if($Nowpage <= 2){
                 
            //      $wheretwos['count']   = ['gt',1000];
                 
            //  }else{
                 
            //      if(1 == rand(1,2)){
               
            //         $timer = date("Y-m-d",strtotime("-20 day"));
            //         $wheretwos['shijian'] = ['gt',$timer];
            //         $wheretwos['count'] = ['gt',1200];
            //      }else{
            //          if(1 == rand(1,2)){
            //              $wheretwos['count'] = ['gt',800];
            //          }else{
            //              $wheretwos['count'] = ['gt',600];
            //          }
                    
            //      }
            //  }
            
             
            $lists = Db::name("gongyou")->where($wheretwos)->order('rand()')->limit(16)->field('id,photo,url,name,pianku,count,times')->select();
          
        }
        
        
        if(!empty($sousuo))
        {
            $wheretwoss['del']   = 1;
          
            $wheretwoss['name'] = ['like', "%" . $sousuo . "%"];
           
            if($Nowpage > 5){
                $Nowpage = 1;
            }
          
            $lists = Db::name("gongyou")->where($wheretwoss)->page($Nowpage, 20)->order('id desc')->field('id,photo,url,name,count,pianku,times')->select();
          
            
        }
        
     
       
        
       
        $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
        
        
        
        $image      = Cache::store('redis')->get('ylimage_urlz');
        
      
        
        //支付通道
        
        $paytypes = Db::name('config')->where(['name' => 'paytypes'])->value('value');
        
        $baoinfo = Db::name('pian')->where(['userid' => $userid])->find();
        
        $is_baotian = $baoinfo['is_baotian'];
      
        $b_money    = $baoinfo['b_money'];
        
        $money      = $baoinfo['money'];

       
       
        foreach($lists as &$v)
        {
            $url     = $v['photo'];
            //正则表达式
            $reg = '/(http):\/\/([^\/]+)/i';
            preg_match($reg, $url,$res);
            
            //pianku  == 1 主  2 备
            if($v['pianku'] == 1){
                
                $url1 = Cache::store('redis')->get('ylimage_urlz');
                
            }
            
            $v['photo']     =  preg_replace($reg,'http://'.$url1, $url);

            // $imgbase = Db::name('config')->where(['name' => 'imgbase'])->value('value');
            
            if(true){
                $v['photo']    = substr($v['photo'],0,strlen($v['photo'])-4);
            }
            
            //随机落地
            $short = substr($ename,3);
            $ename = $this->getRandChar(6);
            $ename = $ename.$short;
            
            $longurl = "http://".$ename ."/index/pay/payinfo.html?userid=" . $jiami_id . '&zyid=' . $v['id'] . "&code=" . $jiami_id."&uopenid=".$uopenid. '&money=' . $money."&ddh=".$ddh2."&b_money=".$b_money;
            
            
            if($gettype == 1000){
                $longurl = "http://".$ename ."/index/pay/guankan.html?userid=" . $jiami_id . '&zyid=' . $v['id'] . "&code=" . $jiami_id."&uopenid=".$uopenid. '&money=' . $money."&ddh=".$ddh2;
            }
            
        
            $v['money'] = $money;
            
            $v['name'] = base64_encode($v['name']);
            
            // if($userid == 201168){
                
            // }
            
            if($v['count'] >= 400){
                $v['count'] = "";
                $v['fuhao'] = "";
            }else{
                $v['count'] = "";
                $v['fuhao'] = "";
            }
          
            unset($v['url']);
           
            $v['dwz'] = $longurl;
            
            $v['d1'] = rand(4000, 1800);
        }
        unset($v);
        
        return json($lists);
    }
    
    
    public function paycount(){
        $uopenid = input('uopenid');
        $zyid    = input('zyid');
        $xinlu   = input('xinlu');
        Db::name('wrg')->insert(['uopenid' => $uopenid,'zyid' => $zyid,'xinlu' =>  $xinlu,'create_time' => time()]);
    }
    
    public function yanchi(){
        if(!is_weixin()){
            $this->redirect("https://xw.qq.com/");
        }
        
        $zyid         = trim(htmlspecialchars(input("zyid/d",0),ENT_QUOTES));
        $xianlu       = trim(htmlspecialchars(input("xianlu/d",0),ENT_QUOTES));
        $ddh          = trim(htmlspecialchars(input("ddh"),ENT_QUOTES));
        $uopenid      = trim(htmlspecialchars(input("uopenid"),ENT_QUOTES));
        
        if(empty($zyid) || empty($ddh) || empty($uopenid)){
              $this->redirect("https://xw.qq.com/");
        }
        $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
        //随机落地
        $short = substr($ename,3);
        $ename = $this->getRandChar(6);
        $ename = $ename.$short;
        $ddh2 = substr($ddh, 0, 10);
        $info = Db::name('dwz')->where(['ddh' => $ddh2])->find();
        $liebiao['bei_url']  =  "http://" . $ename . "/index/index/hezi.html?userid=" . $info['jiami'] ."&ddh=". $ddh2."&uopenid=".$uopenid;
        $this->assign("zyid", $zyid);
        $this->assign("xianlu", $xianlu);
        $this->assign("ddh", $ddh);
        $this->assign("uopenid", $uopenid);
        $this->assign("liebiao", $liebiao);
        $this->assign('turl',"http://".$ename ."/index/index/shipinok.html");
      
        return $this->fetch();
    }



    public function shipinok()
    {
        if(!is_weixin()){
            $this->redirect("https://xw.qq.com/");
        }
        
        $zyid         = trim(htmlspecialchars(input("zyid/d",0),ENT_QUOTES));
        $xianlu       = trim(htmlspecialchars(input("xianlu/d",0),ENT_QUOTES));
        $ddh          = trim(htmlspecialchars(input("ddh"),ENT_QUOTES));
        $bzyid        = trim(htmlspecialchars(input("bzyid"),ENT_QUOTES));
        $mchOrderNo   = trim(htmlspecialchars(input("mchOrderNo"),ENT_QUOTES));
        
        $fxddh        = trim(htmlspecialchars(input("fxddh"),ENT_QUOTES));
        
        if(!empty($fxddh)){
            $ddh   = $fxddh;
        }
        
        if(!empty($mchOrderNo)){
            
            $ddh   = $mchOrderNo;
        }
        
        $order     = Cache::store('redis')->get($ddh);
		
		$zyid      = $order['zyid'];
		
        $userid    = $order['userid'];
        
        $jiami_id  = $order['jiami'];
        
        $ddh3      = $order['ddh3'];
        
        $uopenid   = $order['uopenid'];
        
        
        if(empty($ddh) || empty($uopenid)){

            die("参数错误1111");
         
        }
        
        $info = Db::name('baotian')->where(['uopenid' => $uopenid])->order('id desc')->find();
        
        if($info && $info['end_time'] > time()){
            
            $zyid = $bzyid;
            
            $is_baotian = 1;
           
        }else{
            $is_baotian = 0;
        }
        
         if(empty($zyid)){
          $zyid =   $order['zyid'];
        }
        
        
     
        //查询是否购买
        $pl_count   = Db::name('ip')->where(['ddh2' => $ddh])->value('pl_count');
        if($pl_count == 0){
          session('useridopenid', $uopenid);
          Db::name("ip")->where(['ddh2' => $ddh])->setInc("pl_count"); 
        }else{
           
            // if(!session("useridopenid") || session("useridopenid") != $uopenid){
            //     die('请重新进入网站');
            // }
        }
      
        $liebiao = Cache::store('redis')->get('ylgongyou'.$zyid);
        
        $liebiao = Db::name("gongyou")->where(['id' => $zyid])->find();
        
        
        // $liebiao = Db::name("gongyou")->where(['id' => $zyid])->find();
        
    
        //  if($liebiao['pianku'] == 1){
          
        //     $liebiao = Db::name("gongyou")->where(['del' => 1,'pianku' => ['neq' , 1]])->limit(1)->order('rand()')->find();
            
        //  }
        
        if($liebiao['pianku'] == 1){
            $url1 =  Db::name('config')->where(['name' => 'cdnz_url'])->value('value');
            $url2 =  Db::name('config')->where(['name' => 'image_urlz'])->value('value');
            // $url1 = "tcdn.sctcjt.cn";
           
            if($xianlu == 1){
                $url1 = "tcdn.sctcjt.cn";
            }
            
            if($xianlu == 2){
                 $url1 = "cdnz.sosots.cn";
            }
            
            if($xianlu == 3){
              $url1 = "wwwcdn1.cn-yun.cn";
            }
            
            if($xianlu == 4){
              $url1 = "wwwcdn1.jxxinqiancheng.com";
            }
          
        }
        
        $url       = $liebiao['url'];
        $image_url = $liebiao['photo'];
        //正则表达式
        $reg = '/(http):\/\/([^\/]+)/i';
        preg_match($reg, $url,$res);
        preg_match($reg, $image_url,$res);
        
        
        // $url2 = Cache::store('redis')->get("ylimage_url");
        
      
         
        $liebiao['url']   =  preg_replace($reg,'http://'.$url1, $url);
        $liebiao['photo'] =  preg_replace($reg,'http://'.$url2, $image_url);
        
        if(true)
        {
            $liebiao['photo'] = substr($liebiao['photo'],0,strlen($liebiao['photo'])-4);
        }
       
        $yifutime = time() - intval(24) * 3600;
        
        $ippd = Db::name("ip")->where(['zyid' => $zyid, "userid" => $userid, "uopenid" => $uopenid, 'shijian' => ['>=', $yifutime]])->find(); //"userid"

        // $ddh2 = substr($ddh, 0, 10);
       
        $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
        
        //随机落地
        $short = substr($ename,3);
        $ename = $this->getRandChar(6);
        $ename = $ename.$short;
       
         if($info && $info['end_time'] > time()){
            
            $zyid = $bzyid;
            
        }else{
            
             if (empty($ippd))
            {
                 $order_d = Db::name('order')->where(['orderid' => $ddh])->find();
            
                  if($order_d['shijian'] + 15 < time()){
                      $liebiao['qie_url']  =  "http://" . $ename . "/index/index/hezi.html?userid=" . $jiami_id ."&ddh=". $ddh3."&uopenid=".$uopenid;
                  }else{
                      $liebiao['qie_url']  =  "http://" . $ename . "/index/index/yanchi.html?userid=" . $jiami_id ."&ddh=". $ddh3."&uopenid=".$uopenid."&zyid=".$zyid."&xianlu=0";//总线路
                  }
                  
                  
               
                $this->redirect($liebiao['qie_url']);
               
            }
            
            
        }
        
        
         if($liebiao['pianku'] == 1){
            
            $time = time().'000';

            $add_playkey = "QAZWSXCde147852369";
            
            $ip   =  getclientip();
            
            $sign =  bin2hex(aes128Encrypt($add_playkey,"timestamp=".$time."&ip=".$ip));
            $liebiao['url'] = $liebiao['url']."?sign=".$sign;  
        }
        
       
        $liebiao['shijian']  = "";
        $liebiao['bei_url']  =  "http://" . $ename . "/index/index/hezi.html?userid=" . $jiami_id ."&ddh=". $ddh3."&uopenid=".$uopenid;
        $liebiao['qie_url']  =  "http://" . $ename . "/index/index/shipinok.html?userid=" . $jiami_id ."&ddh=". $ddh."&zyid=".$zyid."&xianlu=1"."&bzyid=".$bzyid;//总线路
        $liebiao['qie_url1']  =  "http://" . $ename . "/index/index/shipinok.html?userid=" . $jiami_id ."&ddh=". $ddh."&zyid=".$zyid."&xianlu=2"."&bzyid=".$bzyid;//总线路
        
        $liebiao['qie_url2']  =  "http://" . $ename . "/index/index/shipinok.html?userid=" . $jiami_id ."&ddh=". $ddh."&zyid=".$zyid."&xianlu=3"."&bzyid=".$bzyid;//总线路
        $liebiao['qie_url3']  =  "http://" . $ename . "/index/index/shipinok.html?userid=" . $jiami_id ."&ddh=". $ddh."&zyid=".$zyid."&xianlu=4"."&bzyid=".$bzyid;//总线路
  
        $this->assign("liebiao", $liebiao);
        $this->assign("userid", $jiami_id);
        $this->assign("ddh", $ddh3);
        $this->assign("xianlu", $xianlu);
        $this->assign("uopenid", $uopenid);
        $this->assign("sptype", $liebiao['type']);
        
        return $this->fetch(); 
     
    }
    
    public function hezi2(){
        if(!wx_mobile()){
                $this->redirect("https://www.baidu.com/");
        }
        // header('Cache-Control: public, max-age=604800');
       
        $userid      = trim(htmlspecialchars(input('userid'),ENT_QUOTES));
        $ddh2        = trim(htmlspecialchars(input('ddh'),ENT_QUOTES));
        $id          = trim(htmlspecialchars(input('id/d',0),ENT_QUOTES));//废弃
        $uopenid     = trim(htmlspecialchars(input('uopenid'),ENT_QUOTES));
        $gettype     = trim(htmlspecialchars(input('type/d',0),ENT_QUOTES));//type = 1000 是用户已打赏
        $sy          = trim(htmlspecialchars(input('shouye/d',0),ENT_QUOTES));//type = 1000 是用户已打赏
       
        $info = Db::name('dwz')->where(['ddh' => $ddh2])->find();
        
        
        if(empty($userid) || empty($ddh2) || empty($uopenid)  || $ddh2 == "yupUUE5kg2" || $ddh2 == "qg65ZHT8cq"){
              $this->redirect("https://xw.qq.com/");
        }
        
        
        if(!$info){
             $this->redirect("http://a.bdydns.com/");
           
        }
        
        // $info = Cache::store('redis')->get($userid);
        
        // if($info == 'null' || !$info){
        //     $info = Db::name('dwz')->where(['ddh' => $ddh2])->find();
        // }
        // if(!is_weixin()){
        //     $this->redirect("https://xw.qq.com/");
        // }
      
         Db::name("dwz")->where(['ddh' => $ddh2])->setInc("count");
        // $shijian = strtotime(date('Y-m-d'));
        // Db::name("fangwen")->where(['time' => $shijian])->setInc("count");
      
        $jiami_id = $userid;
        
        $userid    = $info['userid'];
        $ddh2      = $info['ddh'];
        $id        = $info['sid'];
        $dwz_type  = $info['dwz_type'];
        $tuif = $info['tuif'];
        $tuit = $info['tuit'];
        
        if(empty($info['tui']) || $info['tui'] === 0){
             $tui['url'] = null;
        }else{
             $tui['url'] = $info['tui']; 
        }
        
       
        
        $member = Db::name("member")->where(['id' => $userid])->find();
        if($member['status'] == 0){
            $this->redirect("https://xw.qq.com/");
        }
       
        $btmoney =  Db::name("pian")->where(['userid' => $userid])->value('b_money');
        
        $info    = Db::name('baotian')->where(['uopenid' => $uopenid])->order('id desc')->find();
        
        if($info && $info['end_time'] > time()){
            $is_baotian = 1;
        }else{
            $is_baotian =  0;
          
        }
        
         //点击打赏视频
        if($sy == 1){
            $yemian  = "hezi1"; 
        }
        
        $zhibo    = Db::name('config')->where(['name' => 'zhibo'])->value('value');
        $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
        //随机落地
        $short = substr($ename,3);
        $ename = $this->getRandChar(6);
        $ename = $ename.$short;
        if($zhibo == 1 && $dwz_type == 1 && $sy != 1){
           
             $zhibo    = "http://" . $ename . "/index/index/zhibo.html?userid=" . $jiami_id ."&ddh=". $ddh2."&uopenid=".$uopenid."&shouye=1";
             $this->redirect($zhibo);
        }
        
        if($dwz_type == 1 && $zhibo == 0){
           
            $yemian   = "hezi2";
            $shouye   = "http://" . $ename . "/index/index/hezi.html?userid=" . $jiami_id ."&ddh=". $ddh2."&uopenid=".$uopenid."&shouye=1";
            $zhibo    = "http://" . $ename . "/index/index/zhibo.html?userid=" . $jiami_id ."&ddh=". $ddh2."&uopenid=".$uopenid."&shouye=1";
        }else{
            $yemian  = "hezi1";
            $shouye  = '';
            $zhibo  = '';
        }
        
     
      
        // $this->assign("tuif", $tuif);
        
        // $this->assign("tuit", $tuit);
       
     
         
        return $this->fetch($yemian,[
             'is_baotian' => $is_baotian,
              'btmoney' => $btmoney,
             'userid' => $jiami_id,
             'tui' => $tui,
             'ddh' => $ddh2,
             'uopenid' => $uopenid,
             'gettype' => $gettype,
             'id' => $id,
             'shouye' => $shouye,
             'zhibo'  =>$zhibo,
             'tuif'  => $tuif,
             'tuit'  => $tuit
        ]); 
       
    }
    
    public function shipin(){
        
         if(!wx_mobile()){
                $this->redirect("https://www.baidu.com/");
        }
        
        $t  = input('_t');//随机短视频
        $mm = input('mm/d',0);//美女视频
        
         if($mm != 0){
            $where = ['type' => 2];
            $type  =  2;
        }else{
            $where = ['type' => 1];
            $type  = 1;
        }
        
        $list = Cache::store('redis')->has('qtshipin1'.$type);

		if(!$list || $list === "null"){
		    $list = Db::name("hezishi")->where($where)->field('url,type')->select();
		      Cache::store('redis')->set('qtshipin1'.$type,json_encode($list),259200);
		}else{
		    $list = Cache::store('redis')->get('qtshipin1'.$type);
		}
		
		$rand = rand(0,14);
		$info = $list[$rand];
      
        // $info = Db::name("hezishi")->where($where)->order('rand()')->limit(1)->field('url,type')->find();
        
        // $time = time().'000';

        // $add_playkey = "qwe98337";
        
        // $ip   =  getclientip();
        
        // $sign =  bin2hex(aes128Encrypt($add_playkey,"timestamp=".$time."&ip=".$ip));
        // $info['url'] = $info['url']."?sign=".$sign;  
        
        $this->redirect($info['url']);
    }
    
    
    public function zhibo(){
        if(!wx_mobile()){
                $this->redirect("https://www.baidu.com/");
        }
        $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
        //随机落地
        $short = substr($ename,3);
        $ename = $this->getRandChar(6);
        $ename = $ename.$short;
        
        $userid      = trim(htmlspecialchars(input('userid'),ENT_QUOTES));
        $ddh2        = trim(htmlspecialchars(input('ddh'),ENT_QUOTES));
        $uopenid     = trim(htmlspecialchars(input('uopenid'),ENT_QUOTES));
        
        $info = Db::name('dwz')->where(['ddh' => $ddh2])->find();
        
        
        if(empty($userid) || empty($ddh2) || empty($uopenid)){
              $this->redirect("https://xw.qq.com/");
        }
        
        
        if(!$info){
             $this->redirect("http://a.bdydns.com/");
           
        }
        
        
        
        // $info = Cache::store('redis')->get($userid);
        
        // if($info == 'null' || !$info){
        //     $info = Db::name('dwz')->where(['ddh' => $ddh2])->find();
        // }
        // if(!is_weixin()){
        //     $this->redirect("https://xw.qq.com/");
        // }
      
         Db::name("dwz")->where(['ddh' => $ddh2])->setInc("count");
        // $shijian = strtotime(date('Y-m-d'));
        // Db::name("fangwen")->where(['time' => $shijian])->setInc("count");
      
        $jiami_id = $userid;
        
        $userid    = $info['userid'];
        $ddh2      = $info['ddh'];
        $id        = $info['sid'];
        
        $zhibo    = Db::name('config')->where(['name' => 'zhibo'])->value('value');
        
        $zhibourl = Db::name('config')->where(['name' => 'zhibourl'])->value('value');
        
        $zhitype  = Db::name('config')->where(['name' => 'zhitype'])->value('value');
        
        if($zhibo == 1){
            $shouye   = "http://" . $ename . "/index/index/hezi.html?userid=" . $jiami_id ."&ddh=". $ddh2."&uopenid=".$uopenid."&shouye=1";
        }else{
            $shouye   = "http://" . $ename . "/index/index/hezi2.html?userid=" . $jiami_id ."&ddh=". $ddh2."&uopenid=".$uopenid."&shouye=0";
        }
        
        $jingp = "http://" . $ename . "/index/index/hezi.html?userid=" . $jiami_id ."&ddh=". $ddh2."&uopenid=".$uopenid."&shouye=1";
        
        
        $tuif = $info['tuif'];
        
        $tuit = $info['tuit'];
      
        $this->assign("jingp", $jingp);
         
        $this->assign("tuif", $tuif);
        
        $this->assign("tuit", $tuit);
      
        $this->assign("shouye", $shouye);
        
        $time = time().'000';
        
        $add_playkey = "qwe98337";
        
        $ip   =  getclientip();
        
        $sign =  bin2hex(aes128Encrypt($add_playkey,"timestamp=".$time."&ip=".$ip));
        
        $zhibourl = $zhibourl."?sign=".$sign;
        
        if($zhitype == 0 && $zhibo == 1){
             $this->redirect($zhibourl);
        }
        
        $this->assign("zhibourl", $zhibourl);
        
        
        if($zhibo == 1)
        {
             return $this->fetch('zzhibo');
            
        }else{
             return $this->fetch(); 
        }
        
       
    }
    
    
    
  
}
